#
#    Pixel War (Cliente) - Cliente de Juego Multiplayer Online
#    Copyright (C) 2010 - Francisco Rivera
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import pygame
from constantes import *
from criaturas import HandlerCriaturas
#from pantalla import Pantalla
from mouse import MouseHandler
from teclado import TecladoHandler
from conexion import Conexion
from bala import HandlerBalas
from tools import JThread
   

class Juego:
    
    def __init__(self, login, host, equipo, pantalla=None):
        self.login = login
        # instanciamos las clases necesarias
        self.balas = HandlerBalas()
        hcriat = HandlerCriaturas()
        self.pantalla = pantalla# or Pantalla()
        self.teclado = TecladoHandler(self.pantalla)
        self.mouse = MouseHandler()
        self.conectar(host, equipo)
        # loop principal
        while JThread.JUGANDO:
            self.pantalla.update()
        
    def comenzar(self):
        self.pantalla.activar()
        self.teclado.activar()
        
    def agregarBala(self, bala):
        self.balas.agregarBala(bala)
        
    def setPrincipal(self, jugador):
        self.principal = jugador
        self.pantalla.setPrincipal(jugador)            
            
    def conectar(self, host, equipo):
        self.conexion = Conexion()            
        if self.conexion.conectar(self, host, equipo):
            self.mouse.activar()
        # no nos pudimos conectar
        else:
            self.login.error_conexion()
            self.salir()

    def salir(self):
        self.pantalla.salir()
